#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"
#include "Motor.h"
#include "Key.h"
#include "FlowLight.h"

uint8_t KeyNum;
int8_t Speed;
int8_t ShowSpeed;

int main(void)
{
	OLED_Init();
	Motor_Init();
	Key_Init();
	FlowLight_Init();
	
	OLED_ShowString(1, 1, "Speed:");
	
	while (1)
	{
		KeyNum = Key_GetNum();
		if (KeyNum == 1)
		{
			Speed += 16;
			ShowSpeed += 20;
			if (Speed > 80)
			{
				Speed = -80;
			}
			if (ShowSpeed > 100)
			{
				ShowSpeed = -100;
			}
		}
		else if (KeyNum == 2)
		{
			Speed -= 16;
			ShowSpeed -= 20;
			if (Speed < -80)
			{
				Speed = 80;
			}
			if (ShowSpeed < -100)
			{
				ShowSpeed = 100;
			}
		}
		else if (KeyNum == 3)
		{
			Speed = 0;
			ShowSpeed = 0;
		}
		Motor_SetSpeed(Speed);
		Flow_Update();
		OLED_ShowSignedNum(1, 7, ShowSpeed, 3);
	}
}
